package com.lili.operate.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lili.model.operate.NoticeMessage;
import com.lili.operate.mapper.NoticeMessageMapper;
import com.lili.operate.service.NoticeMessageService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class NoticeMessageServiceImpl implements NoticeMessageService {

    @Autowired
    NoticeMessageMapper noticeMessageMapper;

    /**
     * 分页查询所有的noticeMessage
     * @param map
     * @return
     */
    @Override
    public Page<NoticeMessage> queryNoticeMessage(Map map) {
        int current=1;
        int size = 2;
        if(map.get("current")!=null)
            current = Integer.parseInt(map.get("current").toString());
        if(map.get("size")!=null)
            current = Integer.parseInt(map.get("size").toString());
        Page<NoticeMessage> page = new Page<>(current,size);
        noticeMessageMapper.selectPage(page,null);

        return page;
    }
    /**
     * 更新关闭开启操作
     * @return
     */
    @Override
    public int updateStatus(long id, String noticeStatus) {
        return noticeMessageMapper.updateNoticeStatus(id,noticeStatus);
    }
    /**
     * 更新noticeMessage
     * @param noticeMessage
     * @return
     */
    @Override
    public int updateNoticeMessage(NoticeMessage noticeMessage) {
        QueryWrapper<NoticeMessage> wrapper = new QueryWrapper<>();
        wrapper.eq("id",noticeMessage.getId());
        int rs = noticeMessageMapper.update(noticeMessage,wrapper);
        return rs;
    }
}
